<?php session_start(); ?>
<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
   <title>注册</title>
   <link rel="stylesheet" href="../css/bootstrap.min.css">
   <script type="text/javascript">
	function validate_form(thisform){
		with(thisform){
			var username = document.getElementById("username");
			var password = document.getElementById("password");
			var password_confirm = document.getElementById("password_confirm"		             );
			if(username.value == ""){
				document.getElementById("username_tip").innerHTML = "用户名                不能为空";
				return false;	
			}
			if(username.value.length <2 ||username.value.length >50){
				document.getElementById("username_tip").innerHTML = "用户名                不符合要求";
				return false;	
			}
			if(password.value == ""){
				document.getElementById("password_tip").innerHTML = "密码不																                能为空";
				return false;
			}
			if(password.value.length < 6 ||password.value.length >20){
				document.getElementById("password_tip").innerHTML = "密码不                符合要求";
				return false;	
			}
			if(password.value != password_confirm.value){
				document.getElementById("password_confirm_tip").innerHTML = "                两次密码输入不一致";
				return false;	
			}
			return true;
		}	
	}
	function clear_tip(thisform){
		with(thisform){
			document.getElementById("username_tip").innerHTML = "";
			document.getElementById("password_tip").innerHTML = "";
			document.getElementById("password_confirm_tip").innerHTML = "";
		}	
	}
	function fresh_confirm_code(image){
		image.src="../public/confirm_code.php";
	}

</script>
<style type="text/css">
	.tip{
		color:#F00;
	}
</style>
</head>
<body>
<div style="margin-left:100px;margin-right:100px;">
	<p align="right" style="margin-top:10px">
		<a href='../home/home.php'>返回首页</a>
	</p>
</div><hr/>
<div style="margin-top:50px;margin-left:250px">
<form class="form-horizontal" role="form"action="../handle/register.php" method="post" onSubmit="return validate_form(this)">
   <div class="form-group">
      <label for="username" class="col-sm-2 control-label">
      	用户名:
      </label>
      <div class="col-sm-4">
         <input type="text" class="form-control" id="username" 
         	name="username" placeholder="请输入用户名(2-20位)" 
            onClick= "clear_tip(this)"/>
      </div>
      <label name="username_tip" id="username_tip" style="color:#F00">
      <?php 
	  	if(isset($_GET['isUserExist'])){
			if($_GET['isUserExist'] == true){
		 		echo "用户名已存在";	
			}
		}
	  ?>
      </label>
   </div>
   <div class="form-group">
      <label for="password" class="col-sm-2 control-label">
      	密    码:
      </label>
      <div class="col-sm-4">
         <input type="password" class="form-control" id="password" 
         name="password" placeholder="请输入密码(6-20位)" 
         onClick="clear_tip(this)"/>
      </div>
      <label name="password_tip" id="password_tip" style="color:#F00">
      </label>
   </div>
   <div class="form-group">
      <label for="password_confirm" class="col-sm-2 control-label">
      	确认密码:
      </label>
      <div class="col-sm-4">
         <input type="password" class="form-control" 
         id="password_confirm"  name="password_confirm" 
         placeholder="请再次输入密码(6-20位)" onClick="clear_tip(this)"/>
      </div>
      <label name="password_confirm_tip" id="password_confirm_tip" 
      style="color:#F00">
      </label>
   </div>
   <div class="form-group">
      <label class="col-sm-2 control-label">
      	验证码:
      </label>
      <div class="col-sm-2">
         <input type="text" class="form-control" 
         id="confirm_code"  name="confirm_code" 
         placeholder="请输入验证码" onClick="clear_tip(this)"/>
      </div>
      <img src="../public/confirm_code.php" onClick="fresh_confirm_code(this)"/>	  <label>(点击切换)</label>
      <label name="confirm_code_tip" id="confirm_code_tip" 
      style="color:#F00">
      	<?php 
			if(isset($_GET['FalseConfirmCode'])){
				if($_GET['FalseConfirmCode'] == true){
		 			echo "验证码错误";
					$_GET['FalseConfirmCode'] = false;
				}
			}
		?>
      </label>
   </div>
   <div class="form-group">
      <div class="col-sm-offset-2 col-sm-1">
         <button type="submit" class="btn btn-default">注册</button>
      </div>
      <div class="col-sm-offset-0 col-sm-1">
          <button type="button" class="btn btn-default" 
          onClick="location='login-face.php'">登陆</button>
      </div>
   </div>
</form>
</div>
<?php require('../public/footer.php');?>
</body>
</html>